/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vista;

import controlador.Controlador;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author Guille
 */
public class HelloMIDlet extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    private Controlador controlador;

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Command comandoSalirPrincipal;
    private Command comandoPrincipal;
    private Command comandoIrPrincipal;
    private Command comandoIrGuardar;
    private Command comandoOKNuevaDescarga;
    private Command comandoOKGuardar;
    private Command comandoOKBienvenida;
    private Command exitCommand;
    private Command comandoOKDescarga;
    private Command comandoOKDescargas;
    private Command comandoOKProxy;
    private Command comandoVolverPrincipal;
    private Command comandoIrDescargas;
    private Command itemCommand;
    private Command comandoIrNuevaDescarga;
    private Form principal;
    private ChoiceGroup choiceGroup;
    private Form pantallaInicio;
    private ImageItem imageItem;
    private Form nuevaDescarga;
    private TextField url;
    private StringItem stringItem;
    private Form descarga;
    private Gauge gauge;
    private StringItem stringItem8;
    private Alert error;
    private Form pantallaSalida;
    private ImageItem imageItem1;
    private StringItem stringItem9;
    private Form proxy;
    private ChoiceGroup choiceGroup2;
    private StringItem stringItem7;
    private TextField textField2;
    private TextField textField1;
    private Form verDescarga;
    private StringItem stringItem2;
    private StringItem stringItem1;
    private StringItem stringItem4;
    private StringItem stringItem3;
    private StringItem stringItem6;
    private StringItem stringItem5;
    private Form descargas;
    private ChoiceGroup choiceGroup1;
    private FileBrowser guardar;
    private Image image1;
    //</editor-fold>//GEN-END:|fields|0|

    /**
     * The HelloMIDlet constructor.
     */
    public HelloMIDlet() {
        controlador = new Controlador();
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getPantallaInicio());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == descarga) {//GEN-BEGIN:|7-commandAction|1|59-preAction
            if (command == comandoOKDescarga) {//GEN-END:|7-commandAction|1|59-preAction
                // write pre-action user code here
                switchDisplayable(null, getPrincipal());//GEN-LINE:|7-commandAction|2|59-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|3|71-preAction
        } else if (displayable == descargas) {
            if (command == comandoOKDescargas) {//GEN-END:|7-commandAction|3|71-preAction
                // write pre-action user code here
                switchDisplayable(null, getVerDescarga());//GEN-LINE:|7-commandAction|4|71-postAction
                // write post-action user code here
            } else if (command == comandoVolverPrincipal) {//GEN-LINE:|7-commandAction|5|68-preAction
                // write pre-action user code here
                switchDisplayable(null, getPrincipal());//GEN-LINE:|7-commandAction|6|68-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|7|116-preAction
        } else if (displayable == guardar) {
            if (command == FileBrowser.SELECT_FILE_COMMAND) {//GEN-END:|7-commandAction|7|116-preAction
                // write pre-action user code here
                try
                {
                    switchDisplayable(null, getDescarga());
                    String ruta = getGuardar().getSelectedFileURL();
                    System.out.println(ruta);
                    ruta = ruta.substring(0,ruta.indexOf("G"));
                    System.out.println(ruta);
                    controlador.setGauge(getGauge());
                    controlador.comenzarDescarga(ruta);

                }catch(Exception ex)
                {
                    ex.printStackTrace();
                }
                switchDisplayable(null, getDescarga());//GEN-LINE:|7-commandAction|8|116-postAction
                // write post-action user code here
            } else if (command == comandoIrNuevaDescarga) {//GEN-LINE:|7-commandAction|9|119-preAction
                // write pre-action user code here
                try {
                    // write post-action user code here

                } catch (Exception ex) {
                    ex.printStackTrace();
                    // que salga un alert...
                }
                switchDisplayable(null, getNuevaDescarga());//GEN-LINE:|7-commandAction|10|119-postAction

            }//GEN-BEGIN:|7-commandAction|11|38-preAction
        } else if (displayable == nuevaDescarga) {
            if (command == comandoIrPrincipal) {//GEN-END:|7-commandAction|11|38-preAction
                // write pre-action user code here
                switchDisplayable(null, getPrincipal());//GEN-LINE:|7-commandAction|12|38-postAction
                // write post-action user code here
            } else if (command == comandoOKNuevaDescarga) {//GEN-LINE:|7-commandAction|13|41-preAction
                // write pre-action user code here
                try
                {
                    controlador.crearDescarga(url.getString());
                    System.out.println(url.getString());
                    switchDisplayable(null, getGuardar());//GEN-LINE:|7-commandAction|14|41-postAction
                // write post-action user code here
                }catch(Exception ex)
                {
                    // se muestra una alerta...
                }

            }//GEN-BEGIN:|7-commandAction|15|50-preAction
        } else if (displayable == pantallaInicio) {
            if (command == comandoOKBienvenida) {//GEN-END:|7-commandAction|15|50-preAction
                // write pre-action user code here
                switchDisplayable(null, getPrincipal());//GEN-LINE:|7-commandAction|16|50-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|17|55-preAction
        } else if (displayable == pantallaSalida) {
            if (command == exitCommand) {//GEN-END:|7-commandAction|17|55-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|18|55-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|19|35-preAction
        } else if (displayable == principal) {
            if (command == comandoPrincipal) {//GEN-END:|7-commandAction|19|35-preAction
                // write pre-action user code here
                llamarOpcion();//GEN-LINE:|7-commandAction|20|35-postAction
                // write post-action user code here
            } else if (command == comandoSalirPrincipal) {//GEN-LINE:|7-commandAction|21|19-preAction
                // write pre-action user code here
                switchDisplayable(null, getPantallaSalida());//GEN-LINE:|7-commandAction|22|19-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|23|65-preAction
        } else if (displayable == proxy) {
            if (command == comandoOKProxy) {//GEN-END:|7-commandAction|23|65-preAction
                // write pre-action user code here
                switchDisplayable(null, getPrincipal());//GEN-LINE:|7-commandAction|24|65-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|25|74-preAction
        } else if (displayable == verDescarga) {
            if (command == comandoIrDescargas) {//GEN-END:|7-commandAction|25|74-preAction
                // write pre-action user code here
                switchDisplayable(null, getDescargas());//GEN-LINE:|7-commandAction|26|74-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|27|7-postCommandAction
        }//GEN-END:|7-commandAction|27|7-postCommandAction
        // write post-action user code here

    }//GEN-BEGIN:|7-commandAction|28|
    //</editor-fold>//GEN-END:|7-commandAction|28|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoSalirPrincipal ">//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of comandoSalirPrincipal component.
     * @return the initialized component instance
     */
    public Command getComandoSalirPrincipal() {
        if (comandoSalirPrincipal == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
            comandoSalirPrincipal = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit
            // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return comandoSalirPrincipal;
    }
    //</editor-fold>//GEN-END:|18-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: principal ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of principal component.
     * @return the initialized component instance
     */
    public Form getPrincipal() {
        if (principal == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            principal = new Form("HTTPDownloader", new Item[] { getChoiceGroup() });//GEN-BEGIN:|14-getter|1|14-postInit
            principal.addCommand(getComandoSalirPrincipal());
            principal.addCommand(getComandoPrincipal());
            principal.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return principal;
    }
    //</editor-fold>//GEN-END:|14-getter|2|





    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoPrincipal ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of comandoPrincipal component.
     * @return the initialized component instance
     */
    public Command getComandoPrincipal() {
        if (comandoPrincipal == null) {//GEN-END:|34-getter|0|34-preInit
            // write pre-init user code here
            comandoPrincipal = new Command("Ok", Command.OK, 0);//GEN-LINE:|34-getter|1|34-postInit
            // write post-init user code here
        }//GEN-BEGIN:|34-getter|2|
        return comandoPrincipal;
    }
    //</editor-fold>//GEN-END:|34-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoIrPrincipal ">//GEN-BEGIN:|37-getter|0|37-preInit
    /**
     * Returns an initiliazed instance of comandoIrPrincipal component.
     * @return the initialized component instance
     */
    public Command getComandoIrPrincipal() {
        if (comandoIrPrincipal == null) {//GEN-END:|37-getter|0|37-preInit
            // write pre-init user code here
            comandoIrPrincipal = new Command("Back", Command.BACK, 0);//GEN-LINE:|37-getter|1|37-postInit
            // write post-init user code here
        }//GEN-BEGIN:|37-getter|2|
        return comandoIrPrincipal;
    }
    //</editor-fold>//GEN-END:|37-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoOKNuevaDescarga ">//GEN-BEGIN:|40-getter|0|40-preInit
    /**
     * Returns an initiliazed instance of comandoOKNuevaDescarga component.
     * @return the initialized component instance
     */
    public Command getComandoOKNuevaDescarga() {
        if (comandoOKNuevaDescarga == null) {//GEN-END:|40-getter|0|40-preInit
            // write pre-init user code here
            comandoOKNuevaDescarga = new Command("Ok", Command.OK, 0);//GEN-LINE:|40-getter|1|40-postInit
            // write post-init user code here
        }//GEN-BEGIN:|40-getter|2|
        return comandoOKNuevaDescarga;
    }
    //</editor-fold>//GEN-END:|40-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoIrGuardar ">//GEN-BEGIN:|43-getter|0|43-preInit
    /**
     * Returns an initiliazed instance of comandoIrGuardar component.
     * @return the initialized component instance
     */
    public Command getComandoIrGuardar() {
        if (comandoIrGuardar == null) {//GEN-END:|43-getter|0|43-preInit
            // write pre-init user code here
            comandoIrGuardar = new Command("Back", Command.BACK, 0);//GEN-LINE:|43-getter|1|43-postInit
            // write post-init user code here
        }//GEN-BEGIN:|43-getter|2|
        return comandoIrGuardar;
    }
    //</editor-fold>//GEN-END:|43-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoOKGuardar ">//GEN-BEGIN:|46-getter|0|46-preInit
    /**
     * Returns an initiliazed instance of comandoOKGuardar component.
     * @return the initialized component instance
     */
    public Command getComandoOKGuardar() {
        if (comandoOKGuardar == null) {//GEN-END:|46-getter|0|46-preInit
            // write pre-init user code here
            comandoOKGuardar = new Command("Ok", Command.OK, 0);//GEN-LINE:|46-getter|1|46-postInit
            // write post-init user code here
        }//GEN-BEGIN:|46-getter|2|
        return comandoOKGuardar;
    }
    //</editor-fold>//GEN-END:|46-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoOKBienvenida ">//GEN-BEGIN:|49-getter|0|49-preInit
    /**
     * Returns an initiliazed instance of comandoOKBienvenida component.
     * @return the initialized component instance
     */
    public Command getComandoOKBienvenida() {
        if (comandoOKBienvenida == null) {//GEN-END:|49-getter|0|49-preInit
            // write pre-init user code here
            comandoOKBienvenida = new Command("Ok", Command.OK, 0);//GEN-LINE:|49-getter|1|49-postInit
            // write post-init user code here
        }//GEN-BEGIN:|49-getter|2|
        return comandoOKBienvenida;
    }
    //</editor-fold>//GEN-END:|49-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|54-getter|0|54-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|54-getter|0|54-preInit
            // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|54-getter|1|54-postInit
            // write post-init user code here
        }//GEN-BEGIN:|54-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|54-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoOKDescarga ">//GEN-BEGIN:|58-getter|0|58-preInit
    /**
     * Returns an initiliazed instance of comandoOKDescarga component.
     * @return the initialized component instance
     */
    public Command getComandoOKDescarga() {
        if (comandoOKDescarga == null) {//GEN-END:|58-getter|0|58-preInit
            // write pre-init user code here
            comandoOKDescarga = new Command("Ok", Command.OK, 0);//GEN-LINE:|58-getter|1|58-postInit
            // write post-init user code here
        }//GEN-BEGIN:|58-getter|2|
        return comandoOKDescarga;
    }
    //</editor-fold>//GEN-END:|58-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoOKProxy ">//GEN-BEGIN:|64-getter|0|64-preInit
    /**
     * Returns an initiliazed instance of comandoOKProxy component.
     * @return the initialized component instance
     */
    public Command getComandoOKProxy() {
        if (comandoOKProxy == null) {//GEN-END:|64-getter|0|64-preInit
            // write pre-init user code here
            comandoOKProxy = new Command("Ok", Command.OK, 0);//GEN-LINE:|64-getter|1|64-postInit
            // write post-init user code here
        }//GEN-BEGIN:|64-getter|2|
        return comandoOKProxy;
    }
    //</editor-fold>//GEN-END:|64-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoVolverPrincipal ">//GEN-BEGIN:|67-getter|0|67-preInit
    /**
     * Returns an initiliazed instance of comandoVolverPrincipal component.
     * @return the initialized component instance
     */
    public Command getComandoVolverPrincipal() {
        if (comandoVolverPrincipal == null) {//GEN-END:|67-getter|0|67-preInit
            // write pre-init user code here
            comandoVolverPrincipal = new Command("Back", Command.BACK, 0);//GEN-LINE:|67-getter|1|67-postInit
            // write post-init user code here
        }//GEN-BEGIN:|67-getter|2|
        return comandoVolverPrincipal;
    }
    //</editor-fold>//GEN-END:|67-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoOKDescargas ">//GEN-BEGIN:|70-getter|0|70-preInit
    /**
     * Returns an initiliazed instance of comandoOKDescargas component.
     * @return the initialized component instance
     */
    public Command getComandoOKDescargas() {
        if (comandoOKDescargas == null) {//GEN-END:|70-getter|0|70-preInit
            // write pre-init user code here
            comandoOKDescargas = new Command("Ok", Command.OK, 0);//GEN-LINE:|70-getter|1|70-postInit
            // write post-init user code here
        }//GEN-BEGIN:|70-getter|2|
        return comandoOKDescargas;
    }
    //</editor-fold>//GEN-END:|70-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoIrDescargas ">//GEN-BEGIN:|73-getter|0|73-preInit
    /**
     * Returns an initiliazed instance of comandoIrDescargas component.
     * @return the initialized component instance
     */
    public Command getComandoIrDescargas() {
        if (comandoIrDescargas == null) {//GEN-END:|73-getter|0|73-preInit
            // write pre-init user code here
            comandoIrDescargas = new Command("Back", Command.BACK, 0);//GEN-LINE:|73-getter|1|73-postInit
            // write post-init user code here
        }//GEN-BEGIN:|73-getter|2|
        return comandoIrDescargas;
    }
    //</editor-fold>//GEN-END:|73-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: choiceGroup ">//GEN-BEGIN:|26-getter|0|26-preInit
    /**
     * Returns an initiliazed instance of choiceGroup component.
     * @return the initialized component instance
     */
    public ChoiceGroup getChoiceGroup() {
        if (choiceGroup == null) {//GEN-END:|26-getter|0|26-preInit
            // write pre-init user code here
            choiceGroup = new ChoiceGroup("Elija una opcion", Choice.EXCLUSIVE);//GEN-BEGIN:|26-getter|1|26-postInit
            choiceGroup.append("Nueva Descarga", null);
            choiceGroup.append("Ver Descargas", null);
            choiceGroup.append("Configurar Proxy", null);
            choiceGroup.setSelectedFlags(new boolean[] { false, false, false });
            choiceGroup.setFont(0, null);
            choiceGroup.setFont(1, null);
            choiceGroup.setFont(2, null);//GEN-END:|26-getter|1|26-postInit

        }//GEN-BEGIN:|26-getter|2|
        return choiceGroup;
    }
    //</editor-fold>//GEN-END:|26-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: pantallaInicio ">//GEN-BEGIN:|25-getter|0|25-preInit
    /**
     * Returns an initiliazed instance of pantallaInicio component.
     * @return the initialized component instance
     */
    public Form getPantallaInicio() {
        if (pantallaInicio == null) {//GEN-END:|25-getter|0|25-preInit
            // write pre-init user code here
            pantallaInicio = new Form("HTTPDownloader", new Item[] { getImageItem() });//GEN-BEGIN:|25-getter|1|25-postInit
            pantallaInicio.addCommand(getComandoOKBienvenida());
            pantallaInicio.setCommandListener(this);//GEN-END:|25-getter|1|25-postInit
            // write post-init user code here
        }//GEN-BEGIN:|25-getter|2|
        return pantallaInicio;
    }
    //</editor-fold>//GEN-END:|25-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: nuevaDescarga ">//GEN-BEGIN:|30-getter|0|30-preInit
    /**
     * Returns an initiliazed instance of nuevaDescarga component.
     * @return the initialized component instance
     */
    public Form getNuevaDescarga() {
        if (nuevaDescarga == null) {//GEN-END:|30-getter|0|30-preInit
            // write pre-init user code here
            nuevaDescarga = new Form("HTTPDownloader > Nueva Descarga", new Item[] { getStringItem(), getUrl() });//GEN-BEGIN:|30-getter|1|30-postInit
            nuevaDescarga.addCommand(getComandoIrPrincipal());
            nuevaDescarga.addCommand(getComandoOKNuevaDescarga());
            nuevaDescarga.setCommandListener(this);//GEN-END:|30-getter|1|30-postInit
            // write post-init user code here


        }//GEN-BEGIN:|30-getter|2|
        return nuevaDescarga;
    }
    //</editor-fold>//GEN-END:|30-getter|2|



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: descarga ">//GEN-BEGIN:|32-getter|0|32-preInit
    /**
     * Returns an initiliazed instance of descarga component.
     * @return the initialized component instance
     */
    public Form getDescarga() {
        if (descarga == null) {//GEN-END:|32-getter|0|32-preInit
            // write pre-init user code here
            descarga = new Form("HTTPDownloader > Descargando ...", new Item[] { getStringItem8(), getGauge() });//GEN-BEGIN:|32-getter|1|32-postInit
            descarga.addCommand(getComandoOKDescarga());
            descarga.setCommandListener(this);//GEN-END:|32-getter|1|32-postInit
            // write post-init user code here
        }//GEN-BEGIN:|32-getter|2|
        return descarga;
    }
    //</editor-fold>//GEN-END:|32-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: error ">//GEN-BEGIN:|33-getter|0|33-preInit
    /**
     * Returns an initiliazed instance of error component.
     * @return the initialized component instance
     */
    public Alert getError() {
        if (error == null) {//GEN-END:|33-getter|0|33-preInit
            // write pre-init user code here
            error = new Alert("alert");//GEN-BEGIN:|33-getter|1|33-postInit
            error.setTimeout(Alert.FOREVER);//GEN-END:|33-getter|1|33-postInit
            // write post-init user code here
        }//GEN-BEGIN:|33-getter|2|
        return error;
    }
    //</editor-fold>//GEN-END:|33-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: pantallaSalida ">//GEN-BEGIN:|52-getter|0|52-preInit
    /**
     * Returns an initiliazed instance of pantallaSalida component.
     * @return the initialized component instance
     */
    public Form getPantallaSalida() {
        if (pantallaSalida == null) {//GEN-END:|52-getter|0|52-preInit
            // write pre-init user code here
            pantallaSalida = new Form("HTTPDownloader", new Item[] { getImageItem1(), getStringItem9() });//GEN-BEGIN:|52-getter|1|52-postInit
            pantallaSalida.addCommand(getExitCommand());
            pantallaSalida.setCommandListener(this);//GEN-END:|52-getter|1|52-postInit
            // write post-init user code here
        }//GEN-BEGIN:|52-getter|2|
        return pantallaSalida;
    }
    //</editor-fold>//GEN-END:|52-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: descargas ">//GEN-BEGIN:|61-getter|0|61-preInit
    /**
     * Returns an initiliazed instance of descargas component.
     * @return the initialized component instance
     */
    public Form getDescargas() {
        if (descargas == null) {//GEN-END:|61-getter|0|61-preInit
            // write pre-init user code here
            descargas = new Form("HTTPDownloader > Descargas", new Item[] { getChoiceGroup1() });//GEN-BEGIN:|61-getter|1|61-postInit
            descargas.addCommand(getComandoVolverPrincipal());
            descargas.addCommand(getComandoOKDescargas());
            descargas.setCommandListener(this);//GEN-END:|61-getter|1|61-postInit
            // write post-init user code here
        }//GEN-BEGIN:|61-getter|2|
        return descargas;
    }
    //</editor-fold>//GEN-END:|61-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: verDescarga ">//GEN-BEGIN:|62-getter|0|62-preInit
    /**
     * Returns an initiliazed instance of verDescarga component.
     * @return the initialized component instance
     */
    public Form getVerDescarga() {
        if (verDescarga == null) {//GEN-END:|62-getter|0|62-preInit
            // write pre-init user code here
            verDescarga = new Form("HTTPDownloader > Ver Descarga", new Item[] { getStringItem1(), getStringItem2(), getStringItem3(), getStringItem4(), getStringItem5(), getStringItem6() });//GEN-BEGIN:|62-getter|1|62-postInit
            verDescarga.addCommand(getComandoIrDescargas());
            verDescarga.setCommandListener(this);//GEN-END:|62-getter|1|62-postInit
            // write post-init user code here
        }//GEN-BEGIN:|62-getter|2|
        return verDescarga;
    }
    //</editor-fold>//GEN-END:|62-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: proxy ">//GEN-BEGIN:|63-getter|0|63-preInit
    /**
     * Returns an initiliazed instance of proxy component.
     * @return the initialized component instance
     */
    public Form getProxy() {
        if (proxy == null) {//GEN-END:|63-getter|0|63-preInit
            // write pre-init user code here
            proxy = new Form("HTTPDownloader > Configurar Proxy", new Item[] { getStringItem7(), getChoiceGroup2(), getTextField1(), getTextField2() });//GEN-BEGIN:|63-getter|1|63-postInit
            proxy.addCommand(getComandoOKProxy());
            proxy.setCommandListener(this);//GEN-END:|63-getter|1|63-postInit
            // write post-init user code here
        }//GEN-BEGIN:|63-getter|2|
        return proxy;
    }
    //</editor-fold>//GEN-END:|63-getter|2|






    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageItem ">//GEN-BEGIN:|78-getter|0|78-preInit
    /**
     * Returns an initiliazed instance of imageItem component.
     * @return the initialized component instance
     */
    public ImageItem getImageItem() {
        if (imageItem == null) {//GEN-END:|78-getter|0|78-preInit
            // write pre-init user code here
            imageItem = new ImageItem("Gestor de Descargas", getImage1(), ImageItem.LAYOUT_CENTER | Item.LAYOUT_TOP | Item.LAYOUT_BOTTOM | Item.LAYOUT_VCENTER, "<Missing Image>");//GEN-LINE:|78-getter|1|78-postInit
            // write post-init user code here
        }//GEN-BEGIN:|78-getter|2|
        return imageItem;
    }
    //</editor-fold>//GEN-END:|78-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image1 ">//GEN-BEGIN:|79-getter|0|79-preInit
    /**
     * Returns an initiliazed instance of image1 component.
     * @return the initialized component instance
     */
    public Image getImage1() {
        if (image1 == null) {//GEN-END:|79-getter|0|79-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|79-getter|1|79-@java.io.IOException
                image1 = Image.createImage("/imagenes/download_manager.png");
            } catch (java.io.IOException e) {//GEN-END:|79-getter|1|79-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|79-getter|2|79-postInit
            // write post-init user code here
        }//GEN-BEGIN:|79-getter|3|
        return image1;
    }
    //</editor-fold>//GEN-END:|79-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|80-getter|0|80-preInit
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {//GEN-END:|80-getter|0|80-preInit
            // write pre-init user code here
            stringItem = new StringItem("", "Escriba la URL del archivo a descargar.");//GEN-LINE:|80-getter|1|80-postInit
            // write post-init user code here
        }//GEN-BEGIN:|80-getter|2|
        return stringItem;
    }
    //</editor-fold>//GEN-END:|80-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: url ">//GEN-BEGIN:|81-getter|0|81-preInit
    /**
     * Returns an initiliazed instance of url component.
     * @return the initialized component instance
     */
    public TextField getUrl() {
        if (url == null) {//GEN-END:|81-getter|0|81-preInit
            // write pre-init user code here
            url = new TextField("URL", "http://", 200, TextField.ANY);//GEN-LINE:|81-getter|1|81-postInit
            // write post-init user code here
        }//GEN-BEGIN:|81-getter|2|
        return url;
    }
    //</editor-fold>//GEN-END:|81-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand ">//GEN-BEGIN:|82-getter|0|82-preInit
    /**
     * Returns an initiliazed instance of itemCommand component.
     * @return the initialized component instance
     */
    public Command getItemCommand() {
        if (itemCommand == null) {//GEN-END:|82-getter|0|82-preInit
            // write pre-init user code here
            itemCommand = new Command("Item", Command.ITEM, 0);//GEN-LINE:|82-getter|1|82-postInit
            // write post-init user code here
        }//GEN-BEGIN:|82-getter|2|
        return itemCommand;
    }
    //</editor-fold>//GEN-END:|82-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem8 ">//GEN-BEGIN:|99-getter|0|99-preInit
    /**
     * Returns an initiliazed instance of stringItem8 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem8() {
        if (stringItem8 == null) {//GEN-END:|99-getter|0|99-preInit
            // write pre-init user code here
            stringItem8 = new StringItem("Descargando el archivo", null);//GEN-LINE:|99-getter|1|99-postInit
            // write post-init user code here
        }//GEN-BEGIN:|99-getter|2|
        return stringItem8;
    }
    //</editor-fold>//GEN-END:|99-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: gauge ">//GEN-BEGIN:|100-getter|0|100-preInit
    /**
     * Returns an initiliazed instance of gauge component.
     * @return the initialized component instance
     */
    public Gauge getGauge() {
        if (gauge == null) {//GEN-END:|100-getter|0|100-preInit
            // write pre-init user code here
            gauge = new Gauge("", false, 100, 0);//GEN-LINE:|100-getter|1|100-postInit
            // write post-init user code here
        }//GEN-BEGIN:|100-getter|2|
        return gauge;
    }
    //</editor-fold>//GEN-END:|100-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageItem1 ">//GEN-BEGIN:|102-getter|0|102-preInit
    /**
     * Returns an initiliazed instance of imageItem1 component.
     * @return the initialized component instance
     */
    public ImageItem getImageItem1() {
        if (imageItem1 == null) {//GEN-END:|102-getter|0|102-preInit
            // write pre-init user code here
            imageItem1 = new ImageItem("", getImage1(), ImageItem.LAYOUT_CENTER | Item.LAYOUT_TOP | Item.LAYOUT_BOTTOM | Item.LAYOUT_VCENTER, "<Missing Image>");//GEN-LINE:|102-getter|1|102-postInit
            // write post-init user code here
        }//GEN-BEGIN:|102-getter|2|
        return imageItem1;
    }
    //</editor-fold>//GEN-END:|102-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem9 ">//GEN-BEGIN:|103-getter|0|103-preInit
    /**
     * Returns an initiliazed instance of stringItem9 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem9() {
        if (stringItem9 == null) {//GEN-END:|103-getter|0|103-preInit
            // write pre-init user code here
            stringItem9 = new StringItem("Gracias por usar este programa", "\nAutores:\nDiana Lora\nEsneider Gonzalez\nGuillermo Iguaran\nRicardo Ariza\n");//GEN-LINE:|103-getter|1|103-postInit
            // write post-init user code here
        }//GEN-BEGIN:|103-getter|2|
        return stringItem9;
    }
    //</editor-fold>//GEN-END:|103-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: choiceGroup1 ">//GEN-BEGIN:|84-getter|0|84-preInit
    /**
     * Returns an initiliazed instance of choiceGroup1 component.
     * @return the initialized component instance
     */
    public ChoiceGroup getChoiceGroup1() {
        if (choiceGroup1 == null) {//GEN-END:|84-getter|0|84-preInit
            // write pre-init user code here
            choiceGroup1 = new ChoiceGroup("Lista de Descargas", Choice.EXCLUSIVE);//GEN-LINE:|84-getter|1|84-postInit
            // write post-init user code here
        }//GEN-BEGIN:|84-getter|2|
        return choiceGroup1;
    }
    //</editor-fold>//GEN-END:|84-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem1 ">//GEN-BEGIN:|86-getter|0|86-preInit
    /**
     * Returns an initiliazed instance of stringItem1 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem1() {
        if (stringItem1 == null) {//GEN-END:|86-getter|0|86-preInit
            // write pre-init user code here
            stringItem1 = new StringItem("", "Informacion de la Descarga");//GEN-LINE:|86-getter|1|86-postInit
            // write post-init user code here
        }//GEN-BEGIN:|86-getter|2|
        return stringItem1;
    }
    //</editor-fold>//GEN-END:|86-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem2 ">//GEN-BEGIN:|87-getter|0|87-preInit
    /**
     * Returns an initiliazed instance of stringItem2 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem2() {
        if (stringItem2 == null) {//GEN-END:|87-getter|0|87-preInit
            // write pre-init user code here
            stringItem2 = new StringItem("Nombre del archivo", null);//GEN-LINE:|87-getter|1|87-postInit
            // write post-init user code here
        }//GEN-BEGIN:|87-getter|2|
        return stringItem2;
    }
    //</editor-fold>//GEN-END:|87-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem3 ">//GEN-BEGIN:|88-getter|0|88-preInit
    /**
     * Returns an initiliazed instance of stringItem3 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem3() {
        if (stringItem3 == null) {//GEN-END:|88-getter|0|88-preInit
            // write pre-init user code here
            stringItem3 = new StringItem("URL del archivo", null);//GEN-LINE:|88-getter|1|88-postInit
            // write post-init user code here
        }//GEN-BEGIN:|88-getter|2|
        return stringItem3;
    }
    //</editor-fold>//GEN-END:|88-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem4 ">//GEN-BEGIN:|89-getter|0|89-preInit
    /**
     * Returns an initiliazed instance of stringItem4 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem4() {
        if (stringItem4 == null) {//GEN-END:|89-getter|0|89-preInit
            // write pre-init user code here
            stringItem4 = new StringItem("Tama\u00F1o del archivo", null);//GEN-LINE:|89-getter|1|89-postInit
            // write post-init user code here
        }//GEN-BEGIN:|89-getter|2|
        return stringItem4;
    }
    //</editor-fold>//GEN-END:|89-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem5 ">//GEN-BEGIN:|90-getter|0|90-preInit
    /**
     * Returns an initiliazed instance of stringItem5 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem5() {
        if (stringItem5 == null) {//GEN-END:|90-getter|0|90-preInit
            // write pre-init user code here
            stringItem5 = new StringItem("Tiempo de descarga", null);//GEN-LINE:|90-getter|1|90-postInit
            // write post-init user code here
        }//GEN-BEGIN:|90-getter|2|
        return stringItem5;
    }
    //</editor-fold>//GEN-END:|90-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem6 ">//GEN-BEGIN:|91-getter|0|91-preInit
    /**
     * Returns an initiliazed instance of stringItem6 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem6() {
        if (stringItem6 == null) {//GEN-END:|91-getter|0|91-preInit
            // write pre-init user code here
            stringItem6 = new StringItem("Fecha de descarga", null);//GEN-LINE:|91-getter|1|91-postInit
            // write post-init user code here
        }//GEN-BEGIN:|91-getter|2|
        return stringItem6;
    }
    //</editor-fold>//GEN-END:|91-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem7 ">//GEN-BEGIN:|92-getter|0|92-preInit
    /**
     * Returns an initiliazed instance of stringItem7 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem7() {
        if (stringItem7 == null) {//GEN-END:|92-getter|0|92-preInit
            // write pre-init user code here
            stringItem7 = new StringItem("", "Configuracion de Proxy");//GEN-LINE:|92-getter|1|92-postInit
            // write post-init user code here
        }//GEN-BEGIN:|92-getter|2|
        return stringItem7;
    }
    //</editor-fold>//GEN-END:|92-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: choiceGroup2 ">//GEN-BEGIN:|93-getter|0|93-preInit
    /**
     * Returns an initiliazed instance of choiceGroup2 component.
     * @return the initialized component instance
     */
    public ChoiceGroup getChoiceGroup2() {
        if (choiceGroup2 == null) {//GEN-END:|93-getter|0|93-preInit
            // write pre-init user code here
            choiceGroup2 = new ChoiceGroup("Tipo de Proxy", Choice.POPUP);//GEN-BEGIN:|93-getter|1|93-postInit
            choiceGroup2.append("Ninguno", null);
            choiceGroup2.append("SOCKS4", null);
            choiceGroup2.append("SOCKS5", null);
            choiceGroup2.append("HTTP", null);
            choiceGroup2.setSelectedFlags(new boolean[] { false, false, false, false });
            choiceGroup2.setFont(0, null);
            choiceGroup2.setFont(1, null);
            choiceGroup2.setFont(2, null);
            choiceGroup2.setFont(3, null);//GEN-END:|93-getter|1|93-postInit
            // write post-init user code here
        }//GEN-BEGIN:|93-getter|2|
        return choiceGroup2;
    }
    //</editor-fold>//GEN-END:|93-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField1 ">//GEN-BEGIN:|97-getter|0|97-preInit
    /**
     * Returns an initiliazed instance of textField1 component.
     * @return the initialized component instance
     */
    public TextField getTextField1() {
        if (textField1 == null) {//GEN-END:|97-getter|0|97-preInit
            // write pre-init user code here
            textField1 = new TextField("Host", null, 32, TextField.ANY);//GEN-LINE:|97-getter|1|97-postInit
            // write post-init user code here
        }//GEN-BEGIN:|97-getter|2|
        return textField1;
    }
    //</editor-fold>//GEN-END:|97-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField2 ">//GEN-BEGIN:|98-getter|0|98-preInit
    /**
     * Returns an initiliazed instance of textField2 component.
     * @return the initialized component instance
     */
    public TextField getTextField2() {
        if (textField2 == null) {//GEN-END:|98-getter|0|98-preInit
            // write pre-init user code here
            textField2 = new TextField("Puerto", null, 32, TextField.ANY);//GEN-LINE:|98-getter|1|98-postInit
            // write post-init user code here
        }//GEN-BEGIN:|98-getter|2|
        return textField2;
    }
    //</editor-fold>//GEN-END:|98-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: llamarOpcion ">//GEN-BEGIN:|104-switch|0|104-preSwitch
    /**
     * Performs an action assigned to the llamarOpcion switch-point.
     */
    public void llamarOpcion() {//GEN-END:|104-switch|0|104-preSwitch
        // enter pre-switch user code here
        switch (getChoiceGroup().getSelectedIndex()) {//GEN-BEGIN:|104-switch|1|106-preAction
            case 0://GEN-END:|104-switch|1|106-preAction
                // write pre-action user code here
                switchDisplayable(null, getNuevaDescarga());//GEN-LINE:|104-switch|2|106-postAction
                // write post-action user code here
                break;//GEN-BEGIN:|104-switch|3|108-preAction
            case 1://GEN-END:|104-switch|3|108-preAction
                // write pre-action user code here
                switchDisplayable(null, getDescargas());//GEN-LINE:|104-switch|4|108-postAction
                // write post-action user code here
                break;//GEN-BEGIN:|104-switch|5|112-preAction
            case 2://GEN-END:|104-switch|5|112-preAction
                // write pre-action user code here
                switchDisplayable(null, getProxy());//GEN-LINE:|104-switch|6|112-postAction
                // write post-action user code here
                break;//GEN-BEGIN:|104-switch|7|104-postSwitch
        }//GEN-END:|104-switch|7|104-postSwitch
        // enter post-switch user code here
    }//GEN-BEGIN:|104-switch|8|
    //</editor-fold>//GEN-END:|104-switch|8|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: comandoIrNuevaDescarga ">//GEN-BEGIN:|118-getter|0|118-preInit
    /**
     * Returns an initiliazed instance of comandoIrNuevaDescarga component.
     * @return the initialized component instance
     */
    public Command getComandoIrNuevaDescarga() {
        if (comandoIrNuevaDescarga == null) {//GEN-END:|118-getter|0|118-preInit
            // write pre-init user code here
            comandoIrNuevaDescarga = new Command("Back", Command.BACK, 0);//GEN-LINE:|118-getter|1|118-postInit
            // write post-init user code here
        }//GEN-BEGIN:|118-getter|2|
        return comandoIrNuevaDescarga;
    }
    //</editor-fold>//GEN-END:|118-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: guardar ">//GEN-BEGIN:|114-getter|0|114-preInit
    /**
     * Returns an initiliazed instance of guardar component.
     * @return the initialized component instance
     */
    public FileBrowser getGuardar() {
        if (guardar == null) {//GEN-END:|114-getter|0|114-preInit
            // write pre-init user code here
            try{
                guardar = new FileBrowser(getDisplay());//GEN-BEGIN:|114-getter|1|114-postInit
                guardar.setTitle("fileBrowser");
                guardar.setCommandListener(this);
                guardar.addCommand(FileBrowser.SELECT_FILE_COMMAND);
                guardar.addCommand(getComandoIrNuevaDescarga());//GEN-END:|114-getter|1|114-postInit
            }catch(Exception ex){
                getError().setString(ex.toString());
                switchDisplayable(null, getError());
            }
            // write post-init user code here
        }//GEN-BEGIN:|114-getter|2|
        return guardar;
    }
    //</editor-fold>//GEN-END:|114-getter|2|

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay () {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable (null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet ();
        } else {
            initialize ();
            startMIDlet ();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }

}
